package org.foundation.jala.jamerzip.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import org.foundation.jala.jamerzip.modelzip.NewZip;

public class NewZipView extends JDialog{

	private static final long serialVersionUID = 1L;
	private NewZip actions;
	private JList list;
	private JTextField dir;
	
    public NewZipView(JFrame father) {
    	super(father,"Compress files ");
        configuration();
        initComponents();
    }

    public JList getList() {
		return list;
	}
    
    public JTextField getDir() {
		return dir;
	}
    public void setActions(NewZip actions) {
		this.actions = actions;
	}
    private void configuration() {
       this.setSize(400, 500);
       this.setMinimumSize(new Dimension(400,500));
       this.setLocationRelativeTo(null);
       this.setLayout(new BorderLayout());
       this.setModal(true);
       this.setResizable(false);
    }

    @SuppressWarnings("serial")
	private void initComponents() {
    	this.list = new JList();
    	JScrollPane scroll = new JScrollPane(list);
    	scroll.setPreferredSize(new Dimension(400, 300));
    	scroll.setMaximumSize(new Dimension(400	, 300));
    	
    	
    	JPanel panelSup = new JPanel();
    	panelSup.setAlignmentX(JPanel.CENTER_ALIGNMENT);
    	panelSup.setLayout(new BorderLayout());
    	panelSup.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20), BorderFactory.createBevelBorder(1)));

    	JButton add = new JButton("Add to Compress");
    	add.addActionListener(new AbstractAction() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				actions.addFile();
			}
		});
    	panelSup.add(scroll,BorderLayout.CENTER);
    	panelSup.add(add,BorderLayout.SOUTH);
    	
    	add(panelSup,BorderLayout.CENTER);
    	
    	JLabel path = new JLabel("Path : ");
    	this.dir = new JTextField("		");
    	JButton search = new JButton("Browse");
    	search.addActionListener(new AbstractAction() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				actions.showTargetPath();
			}
		});
    	
    	JPanel panelBrowse = new JPanel();
    	panelBrowse.setLayout(new BoxLayout(panelBrowse, BoxLayout.X_AXIS));
    	panelBrowse.add(path);
    	panelBrowse.add(dir);
    	panelBrowse.add(search);
    	
    	
    	JButton compress = new JButton("Compress");
    	compress.addActionListener(new AbstractAction() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				actions.compress();
			}
		});
    	JButton cancel = new JButton("Cancel");
    	cancel.addActionListener(new AbstractAction() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
    	JButton ok = new JButton("Ok");
    	ok.setEnabled(false);
    	JPanel panelButtons = new JPanel();
    	panelButtons.setLayout(new FlowLayout(FlowLayout.CENTER));
    	panelButtons.add(compress);
    	panelButtons.add(ok);
    	panelButtons.add(cancel);
    	panelButtons.setAlignmentX(JPanel.CENTER_ALIGNMENT);

    	JPanel panelSouth = new JPanel();
    	panelSouth.setLayout(new BorderLayout());
    	panelSouth.add(panelBrowse,BorderLayout.CENTER);
    	
    	panelSouth.add(panelButtons,BorderLayout.SOUTH);
    	panelSouth.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    	
    	add(panelSouth,BorderLayout.SOUTH);
    }
}
